package hotel.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import hotel.entity.Authority;
import hotel.service.IAuthorityService;

@Component
public class AuthorityServiceImpl<T> extends ServiceImpl<T> implements IAuthorityService<T> {

	@Override
	public List<Authority> findNoAuthority(int roleId) {
		List<Object[]> list=this.dao.sqlQuery("select * from authority where authorityid NOT IN (select authority_id from role_authority where role_id ='"+roleId+"')");
		List<Authority> noAuths=new ArrayList<>();
		for(Object[] obj:list) {
			Authority a=new Authority();
			a.setPath((String)obj[4]);
			noAuths.add(a);
		}		
		return noAuths;
	}

	@Override
	public List<T> findAllAuthority() {
		return dao.list("from Authority a order by a.authorityName");
	}
	
	@Override
	public List<T> listAll(String entityName){
		return this.findAllAuthority();
	}

}
